/* ----------------------------------------------------------------------------------------------------------------
 * Despair
 * ----------------------------------------------------------------------------------------------------------------
 */

/*
   待解决 :
	   
			0. 世界 & 实体交互行为    ---> ＃ 紧急 - （暂时仅为滑鼠交互，触摸交互待定）
	   
			1. 状态 / 行为(Status)    ---> ＃ 紧急 - （解决方式）Status
			
			2. 实体定位/移动/角度     ---> ＃ 紧急 - （解决方式）...

			--------------------------------------------------------------------------------
			
			3. 布景(Scenery)平滑移动  ---> ＃ 优化 - （解决方式）Blitmask滚动
			
			4. 声音(Sound)            ---> ＃ 紧急 - 
						
			5. 四叉树(Quadtree)       ---> ＃ 优化 - 
			
			6. 寻路(Path)             ---> ＃ 优化 - 
			
			7. 资源加载(Resource)     ---> ＃ 再议 - 
			
			8. 网络通信(net)          ---> ＃ 再议 - 
			
			9. 分时处理(Delay)        ---> ＃ 优化 -
			
			10. 单监视器模式(Monitor) ---> ＃ 优化 - 
 */ 

package pure.engine 
{
	import flash.display.DisplayObjectContainer;
	import flash.display.LoaderInfo;
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.events.IEventDispatcher;
	import flash.system.ApplicationDomain;
	
	import pure.engine.entity.EntityManager;
	import pure.engine.entity.EntityPool;
	import pure.engine.entity.IEntity;
	import pure.engine.renderer.sections.Section;
	import pure.engine.renderer.sections.SectionManager;
	import pure.engine.system.InputManager;
	import pure.engine.system.SystemManager;
	
	import pure.engine.world.WorldBody;
	import pure.engine.world.WorldContent;
	import pure.engine.world.WorldManager;
	import pure.engine.system.ns_despair;
	use namespace ns_despair;
	
	/**
	 * Pure - Despair
	 * 
	 * @author ＃Pure
	 * 
	 */
public class Despair
{
	

	/**
	 * 启动
	 * 
	 * @param owner
	 */
	public static function startup(owner:DisplayObjectContainer):void
	{
		SystemManager.initialize(owner);
		m_input = new InputManager();
	}
	
    	
	
		
	//======================
	// System
	//======================
	
	
	// 输入管理器
	public static function get input():InputManager { return m_input; }
	
	// 事件侦听器
	public static function get notifier():IEventDispatcher { return SystemManager.m_notifier; }
	
	// 舞台
	public static function get stage():Stage { return SystemManager.m_stage; }
    public static function get root():DisplayObjectContainer { return SystemManager.m_root; }
	
	
	
	
	//======================
	// Application Domain
	//======================
    
	
    /**
     * 加入应用域信息
     * 
     * @param loaderInfo
     */
    public static function addApplicationDomainInfo(loaderInfo:LoaderInfo):void
    {
        SystemManager.addApplicationDomainInfo(loaderInfo);
    }
    
    
    /**
     * 获取类定义
     * 
     * @param className
     */
    public static function getDefinition(className:String):Class
    {
        return SystemManager.getDefinition(className);
    }
	
	
    /**
     * 清理应用域
	 * 
	 * <HINT> 加载SWF时可用，减少内存占用.
     * 
     * @param className
     */
    public static function clearup():void
    {
        return SystemManager.clearup();
    }
    
    
	
	
	
	//======================
	// World
	//======================
	

	/**
	 * 注册世界body
	 * 
	 * @param worldBodyName
	 * @param sortProperty
	 */
	public static function registerWorldBody(worldBodyName:String, sortProperty:String = null):void
	{
		WorldManager.registerWorldBody(worldBodyName, sortProperty);
	}

	
	/**
	 * 改变世界Content
	 * 
	 * @param worldBody
	 * @param worldData
	 */
	public static function setWorldData(worldBodyName:String, worldContent:WorldContent):void
	{
		WorldManager.getWorldBody(worldBodyName).worldContent = worldContent;
	}
	
	
	
	
	
	//======================
	// Monitor
	//======================

	
	/**
	 * 生成监视器
	 * 
	 * @param width
	 * @param height
	 * @param worldBody
	 * @param autoUpdateScope
	 * @param mouseEnabled
	 * @param transitionDuration
	 * @param transitionColor
	 */
	public static function createMonitor(width:Number, height:Number, worldBodyName:String, autoUpdateScope:Boolean, mouseEnabled:Boolean = true, transitionDuration:Number = 0.16, transitionColor:uint = 0):Monitor
	{
		var monitor:Monitor;
		var worldBody:WorldBody;
		
		worldBody = WorldManager.getWorldBody(worldBodyName)
		monitor = new Monitor(width, height,worldBody ,autoUpdateScope, transitionDuration, transitionColor);
		monitor.mouseEnabled = mouseEnabled;
		return monitor;
	}
	
	
	
	
	
	//======================
	// Entity
	//======================
	
	
	// 活着实体数量
	public static function get numAlive():int { return EntityManager.m_numAlive; }
	
	// 可再生实体数量
	public static function get numRevivable():int { return EntityPool.m_numRevivable; }

	
	/**
	 * 注册成品实体
	 * 
	 * @param args
	 */
	public static function registerEntities(...args):void
	{
		EntityManager.registerEntities(args);
	}
		

	/**
	 * 获取实体
	 * 
	 * @param nameOrList
	 */
	public static function getEntities(nameOrList:*):Array
	{
		var result:Array;
		
		if (nameOrList is String)
		{
			result = EntityManager.getEntitiesByName(nameOrList);
		}
		else if (nameOrList is Array)
		{
			result = EntityManager.getEntitiesByNames(nameOrList);
		}
		return result;
	}
	
	
	
	
	
	//======================
	// Section
	//======================
		
	
	
	// 片段数量
	public static function get numSection():int 
	{ 
		return SectionManager.m_numSection;
	}
	
	
	/**
	 * 注册片段
	 * 
	 * @param data
	 */
	public static function registerSections(data:XML):void
	{
		SectionManager.registerSections(data);
	}

	
	/**
	 * 快速生成SWF片段
	 * 
	 * @param name
	 * @param SWF
	 * @param params
	 */
	public static function makeSectionBySWF(name:String, SWF:MovieClip, ...params):void
	{
		SectionManager.makeSectionBySWF(name,SWF, params);
	}
	

	
	private static var m_input:InputManager;

}

}